﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="isikType_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(IsikTypeV4))]
    public class IsikTypeV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IIsikTypeV4 clazz;
        
        public IsikTypeV4Serializer(IIsikTypeV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tegevus");
            if (clazz.Tegevus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tegevus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("liik");
            if (clazz.Liik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Liik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Liik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("roll");
            if (clazz.Roll!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Roll))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Roll");
            }
            Writer.WriteEndElement();
            if (clazz.VolitusteTahtaeg!=null) {
                Writer.WriteStartElement("volituste_tahtaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.VolitusteTahtaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SissemaksuSumma!=null) {
                Writer.WriteStartElement("sissemaksu_summa");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.SissemaksuSumma))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SissemaksuValuuta!=null) {
                Writer.WriteStartElement("sissemaksu_valuuta");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SissemaksuValuuta))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SissemaksuLugeja!=null) {
                Writer.WriteStartElement("sissemaksu_lugeja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.SissemaksuLugeja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SissemaksuNimetaja!=null) {
                Writer.WriteStartElement("sissemaksu_nimetaja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.SissemaksuNimetaja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Eesnimi!=null) {
                Writer.WriteStartElement("eesnimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("nimi");
            if (clazz.Nimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nimi");
            }
            Writer.WriteEndElement();
            if (clazz.Synniaeg!=null) {
                Writer.WriteStartElement("synniaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Synniaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kood!=null) {
                Writer.WriteStartElement("kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Valiskood!=null) {
                Writer.WriteStartElement("valiskood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Valiskood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ValiskoodRiik!=null) {
                Writer.WriteStartElement("valiskood_riik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ValiskoodRiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Aadress!=null) {
                Writer.WriteStartElement("aadress");
                global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData(clazz.Aadress);
                Writer.WriteTypeAttribute(metaAadress.TypeQualifiedName.Namespace, metaAadress.TypeQualifiedName.Name);
                metaAadress.NewSerializer(clazz.Aadress).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Residentsus!=null) {
                Writer.WriteStartElement("residentsus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Residentsus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Email!=null) {
                Writer.WriteStartElement("email");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Email))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kontakt!=null) {
                Writer.WriteStartElement("kontakt");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kontakt))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tegevus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>tegevus");
                }
                clazz.Tegevus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegevus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikType_v4>tegevus", Reader.LocalName);
            }
            if (Reader.LocalName=="liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>liik");
                }
                clazz.Liik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("liik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikType_v4>liik", Reader.LocalName);
            }
            if (Reader.LocalName=="roll") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>roll");
                }
                clazz.Roll = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("roll")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikType_v4>roll", Reader.LocalName);
            }
            if (Reader.LocalName=="volituste_tahtaeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>volituste_tahtaeg");
                }
                clazz.VolitusteTahtaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("volituste_tahtaeg")).Value;
            }
            if (Reader.LocalName=="sissemaksu_summa") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SissemaksuSumma = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("sissemaksu_summa")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="sissemaksu_valuuta") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SissemaksuValuuta = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("sissemaksu_valuuta")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="sissemaksu_lugeja") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>sissemaksu_lugeja");
                }
                clazz.SissemaksuLugeja = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("sissemaksu_lugeja")).Value;
            }
            if (Reader.LocalName=="sissemaksu_nimetaja") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>sissemaksu_nimetaja");
                }
                clazz.SissemaksuNimetaja = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("sissemaksu_nimetaja")).Value;
            }
            if (Reader.LocalName=="eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>eesnimi");
                }
                clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eesnimi")).Value;
            }
            if (Reader.LocalName=="nimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>nimi");
                }
                clazz.Nimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>isikType_v4>nimi", Reader.LocalName);
            }
            if (Reader.LocalName=="synniaeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>synniaeg");
                }
                clazz.Synniaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("synniaeg")).Value;
            }
            if (Reader.LocalName=="kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>kood");
                }
                clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kood")).Value;
            }
            if (Reader.LocalName=="valiskood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>valiskood");
                }
                clazz.Valiskood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valiskood")).Value;
            }
            if (Reader.LocalName=="valiskood_riik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>valiskood_riik");
                }
                clazz.ValiskoodRiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valiskood_riik")).Value;
            }
            if (Reader.LocalName=="aadress") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressTypeV4>(Reader, "aadressType_v4", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Aadress = metaAadress.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressTypeV4>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("aadress");
                        metaAadress.NewSerializer(clazz.Aadress).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="residentsus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Residentsus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("residentsus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="email") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>email");
                }
                clazz.Email = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("email")).Value;
            }
            if (Reader.LocalName=="kontakt") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>isikType_v4>kontakt");
                }
                clazz.Kontakt = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kontakt")).Value;
            }
        }
    }
}
